package com.xiaren.util;

import java.awt.Component;

import com.xiaren.biz.WindowFloatEvent;
import com.xiaren.common.ObjectConstant;

/**
 * @主页 http://www.leaf123.cn/
 * @邮箱 xia5523@qq.com
 */
public class ComponentUtil {
	/**
	 * 改变组件的横向位置位置
	 *
	 * @param x
	 *            原始的x坐标
	 * @param y
	 *            原始的y坐标
	 * @param NewX
	 *            新的x坐标
	 * @param NewY
	 *            新的y坐标
	 * @param componet
	 *            该移动的容器 <br/>
	 *            demo <br/>
	 *            ComponentUtil.moveXComponent(ObjectConstant.titleWindow
	 *            .getX(), ObjectConstant.titleWindow.getY(), 10 -
	 *            ObjectConstant.titleWindow.getWidth() ,
	 *            ObjectConstant.titleWindow.getY(),
	 *            ObjectConstant.titleWindow);
	 */
	public static void moveXComponent(final int x, final int y, final int NewX,
									  final int NewY, final Component componet) {
		final int move = x <= NewX ? 5 : -5;
		new Thread() {
			public void run() {
				int begin = x, end = NewX, temp = 0;
				while (Math.abs(end - begin) > 5) {
					temp = begin += move;
					componet.setLocation(Math.abs(temp - NewX) < 5 ? NewX
							: temp, y);
					try {
						Thread.sleep(2);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}.start();
	}
	/**
	 * 还没测试
	 * @param x
	 * @param y
	 * @param NewX
	 * @param NewY
	 * @param componet
	 */
	public static void moveYComponent(final int x, final int y, final int NewX,
									  final int NewY, final Component componet) {
		final int move = y <= NewY ? 5 : -5;
		new Thread() {
			public void run() {
				int begin = y, end = NewY, temp = 0;
				while (Math.abs(end - begin) > 5) {
					temp = begin += move;
					componet.setLocation(Math.abs(temp - NewY) < 5 ? NewY
							: temp, y);
					try {
						Thread.sleep(2);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}.start();
	}

}
